local yizan = fk.CreateSkill{
    name = "wk_heg__yizan",
}

Fk:loadTranslationTable{
    ["wk_heg__yizan"] = "翼赞",
    [":wk_heg__yizan"] = "弃牌阶段开始时，你可令一名手牌数小于体力上限的其他角色将手牌摸至体力上限，然后此阶段结束时，若你于此阶段内弃置过牌，其将手牌弃至与你相同。",

    ["#wk_heg__yizan-choose"] = "翼赞：选择一名手牌数小于你的角色，令其将手牌摸至体力上限",
    ["#wk_heg__yizan-throw"] = "翼赞：将手牌弃至你的体力上限",

    ["$wk_heg__yizan1"] = "公事为重，宴席不去也罢。",
    ["$wk_heg__yizan2"] = "还是改日吧。",
}

yizan:addEffect(fk.EventPhaseStart,{
    anim_type = "drawcard",
    can_trigger = function (self, event, target, player, data)
       return player:hasSkill(yizan.name) and player.phase == Player.Discard
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local targets = table.filter(room.alive_players, function(p) return p:getHandcardNum() < p.maxHp and p ~= player end)
        if #targets > 0 then
        local to = room:askToChoosePlayers(player,{
            targets = targets,
            min_num = 1,
            max_num = 1,
            prompt = "#wk_heg__yizan-choose",
            skill_name = yizan.name,
            cancelable = true,
        })
        if #to > 0 then
            event:setCostData(self,{ to = to })
            return true
        end
    end
      
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local to = event:getCostData(self).to[1]
        to:drawCards(to.maxHp - #to.player_cards[Player.Hand], yizan.name)
        room:setPlayerMark(player, "wk_heg__yizan-phase", 1)
        room:setPlayerMark(to, "wk_heg__yizan-phase", 1)
    end,
})

yizan:addEffect(fk.EventPhaseEnd,{
    is_delay_effect = true,
    anim_type = "special",
    can_trigger = function (self, event, target, player, data)
        if not (player:hasSkill(yizan.name) and player.phase == Player.Discard and player:getMark("wk_heg__yizan-phase") ~= 0) then return false end
        local logic = player.room.logic
        local x = 0
        logic:getEventsOfScope(GameEvent.MoveCards, 1, function (e)
        for _, move in ipairs(e.data) do
           if move.from == player and move.moveReason == fk.ReasonDiscard and move.skillName == "phase_discard" then
            x = x + #move.moveInfo
            if x > 1 then return true end
          end
        end
        return false
        end, Player.HistoryTurn)
        return x > 0
    end,
    on_cost = Util.TrueFunc,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local targets = table.filter(room:getOtherPlayers(player), function(p) return (p:getMark("wk_heg__yizan-phase") > 0) end)
        local to = targets[1]
        local throw_num = #to.player_cards[Player.Hand] - #player.player_cards[Player.Hand]
        if throw_num > 0 and not to:isKongcheng() then
        room:askToDiscard(to,{
           min_num = throw_num,
           max_num = throw_num,
           prompt = "#wk_heg__yizan-throw",
           include_equip = false,
           skill_name = yizan.name,
           cancelable = false,
        })
      end
    end,
})

return yizan